package beans;
import db.*;import entities.*;

import javax.ejb.Stateless;
import beans.LoanManager;
import java.util.*;
@Stateless
public class LoanManagerBean implements LoanManager {

	public boolean approve(int reqId){
		Request r=DbRequestManager.getRequest(reqId);
		if(r==null || !r.getReqStatus().equals("pending")){
			return false;
		}
		boolean result=DbRequestManager.deleteRequest(reqId);
		if(!result)return false;
		result=DBLoanManager.addLoan(r.getOwnerId(), r.getRequestorId(), r.getCopyId());
		return result;
	}
	

	public ArrayList<Request> getPendingLoans(int userId){
		return DbRequestManager.getAllRequests(userId);
	}


	@Override
	public boolean deny(int reqId) {
		return DbRequestManager.deleteRequest(reqId);
	}
}
